/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author SONY
 */
public class ProductService {
    
    private ProductDAO productDAO;
    private List products;
    
    public ProductService() {       
        productDAO = new ProductDAO();      
    }
    
    /**
     * @return the products
     */
    public List getProducts() {
        try {
            this.products = productDAO.getAllProducts();
        } catch(Exception e) {
            System.err.println(e);
        }
        return products;
    }
    
    public boolean checkQuantity(String pid, int qty) {
        try {
            if(qty <= productDAO.getQOH(pid)) {
                return true;
            }
        } catch (Exception e) {
            System.err.println(e);
        }
        return false;
    }
    
    public Product getProductDetails_byPID(String pid) {
        return productDAO.search_byProductID(pid);
    }
    
    public ArrayList<Product> getProducts_byKeyword(String keyword) {
        ArrayList<Product> lstProducts = new ArrayList<Product>();
        try {
            lstProducts = productDAO.getProducts_byKeyword(keyword);
            
        } catch(Exception e) {
            System.err.println(e);
        }
        return lstProducts;
    }
    
    public boolean changeQOH(String ProductID, int new_QOH) {
        try {
            if(productDAO.update_QOH(ProductID, new_QOH)) {
                return true;
            }
        } catch (Exception e) {
            System.err.println(e);
        }
        return false;
    }    
}
